﻿using LPLS.DBEntities.ConfigModels.DeviceInfoModels;
using LPLS.DBInterface.ConfigModels.DeviceInfoModels;
using LPLS.PluginCommon;
using LPLS.PluginCommon.ModulePlugin;
using Prism.Commands;
using Prism.Dialogs;
using Prism.Ioc;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;

namespace DataCollectionConfigModule.ViewModels
{

    [ViewModelMetadata(projectID: "12322222", viewModelName: "数据采集设备信息配置", version: "1.0.1", lifecycle: Lifecycle.Singleton, index: 0, isCommon: true)]
    public class DataCollectionConfigViewModel : ViewModelBase
    {

        IDeviceBaseInfoService _deviceBaseInfoService;
        public DataCollectionConfigViewModel(IContainerProvider containerProvider, IDeviceBaseInfoService deviceBaseInfoService) : base(containerProvider)
        {
            _deviceBaseInfoService = deviceBaseInfoService;
            QueryCommand = new DelegateCommand(QueryData);
            InitializeTabs();
            LoadData();
        }


        private ObservableCollection<TabItem> _tabItems;
        public ObservableCollection<TabItem> TabItems
        {
            get { return _tabItems; }
            set { SetProperty(ref _tabItems, value); }
        }

        private void InitializeTabs()
        {
            TabItems = new ObservableCollection<TabItem>
        {
           // CreateTabItem("设备基础配置", typeof(DeviceBaseInfoView)),
          //  CreateTabItem("设备部件配置", typeof(DeviceComponentInfoView)),
            //CreateTabItem("报警代码规则配置", typeof(AlarmVarableCodeRuleConfigView)),

        };
        }

        public DelegateCommand QueryCommand { get; }

        #region  设备数据加载 条件筛选
        /// <summary>
        /// 
        /// </summary>
        private void LoadData()
        {
           
            DeviceList = new ObservableCollection<DeviceBaseInfo>(_deviceBaseInfoService.GetData());

        }

        private ObservableCollection<DeviceBaseInfo> _DeviceList;

        public ObservableCollection<DeviceBaseInfo> DeviceList
        {
            get { return _DeviceList; }
            set
            {
                SetProperty(ref _DeviceList, value);

            }
        }

        private DeviceBaseInfo _SelectDeviceModel;
        public DeviceBaseInfo SelectDeviceModel
        {
            get { return _SelectDeviceModel; }
            set
            {

                SetProperty(ref _SelectDeviceModel, value);

            }
        }


        private void QueryData()
        {
          
            if (SelectDeviceModel == null)
            {

                MessageBox.Show("未选择设备");            
                return;
            }
            DataCollectionDeviceEvent.RaiseDataCollectionDeviceChanged(SelectDeviceModel);
        }



        #endregion


    }
}
